var Goods = require('../lib/mongo').Goods;
module.exports = {
    addGoods: function addGoods(goodsInfo) {
        return Goods.create(goodsInfo).exec();
    },
    updateGoods: function updateGoods(id, data) {
        return Goods.update({_id: id}, {$set: data}).exec()
    },
    updateGoodsNum: function updateGoodsNum(id, count){
        return Goods.update({_id: id},{$set: {count: count}}).exec();
    },
    delGoods: function delGoods(id) {
        return Goods.remove({_id: id}).exec();
    },
    getGoods: function getGoods(id) {
        return Goods.find({_id: id}).exec();
    },
    getAllGoods: function getAllGoods() {
        return Goods.find().populate({path: 'user', model: 'User'})
            //.skip(start).limit(10)
            .sort({_id: -1})
            .exec();
    },
    getShopkeeperGoods: function getShopkeeperGoods(user,page){ //获得店主的商品
        var start = (page -1) * 10;
        return Goods.find({user: user})
            .skip(start).limit(10)
            .sort({_id: -1})
            .exec();
    },
    getGoodsCount: function getGoodsCount(data){
        return Goods.count(data).exec();
    }
};